package com.andnux.android.network;


import io.reactivex.functions.Consumer;

public abstract class SuccessConsumer<T> implements Consumer<T> {

    public abstract void onSuccess(T t);

    @Override
    public void accept(T t) throws Exception {
        if (t instanceof Result) {
            Result<?> result = (Result<?>) t;
            if (result.getCode() != 200) {
                throw new RuntimeException(result.getMessage());
            } else {
                onSuccess(t);
            }
        } else {
            throw new RuntimeException("result in not Result<*>");
        }
    }
}
